﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

namespace Livraria
{
    public partial class _Default : System.Web.UI.Page
    {
        SqlConnection conn;
        private void Page_Load(Object Src, EventArgs E)
        {
            //string strConnectionString = @"Data Source=srv-acd-sql;Initial Catalog=bdAsp_lucas;Integrated Security=True";
            string strConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=" + "C:\\Arquivos de programas\\Microsoft SQL Server\\MSSQL.1\\MSSQL\\Data\\bdAsp_Livraria.mdf" + ";Integrated Security=True;Connect Timeout=30;User Instance=True";
            conn = new SqlConnection(strConnectionString);

            if (!IsPostBack)
            {
                BindBG();
            }
        }

        private void BindBG()
        {
            string sqlQuery = "select * from Produtos order by nome asc";
            SqlDataAdapter command = new SqlDataAdapter(sqlQuery, conn);
            DataSet ds = new DataSet();
            command.Fill(ds, "Produtos");
            dgLivraria.DataSource = ds.Tables["Produtos"];
            dgLivraria.DataBind();
        }
    }
}